package com.mingtu.jgspatrol.adapter;

import android.content.Context;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.common.base.BaseApplication;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.bean.MonitoringRecZdPeople;
import com.mingtu.hikvideo2.utils.CalendarUtil;

import java.util.ArrayList;
import java.util.List;

public class MonitoringRecAdapter1 extends BaseQuickAdapter<MonitoringRecZdPeople.DataBean.ListBean, BaseViewHolder> {

    private Context context;
    private List<MonitoringRecZdPeople.DataBean.ListBean> mData = new ArrayList<>();
    private OnItemClickListener mOnItemClickListener = null;

    public MonitoringRecAdapter1(Context context) {
        super(R.layout.item_monitoring_rec1);
        this.context = context;
    }



    @Override
    protected void convert(@NonNull BaseViewHolder helper, MonitoringRecZdPeople.DataBean.ListBean listBean) {
        MonitoringRecZdPeople.DataBean.ListBean.SnapInfoBean snapInfo = listBean.getSnapInfo();
        String imgUrl = snapInfo.getSnapUrl();
        String cameraName = snapInfo.getCameraName();
        String eventTime = snapInfo.getEventTime();

        String gender = snapInfo.getGender();
        String glass = snapInfo.getGlass();
        String age = snapInfo.getAge();

        String genderStr = "";
        String glassStr = "";
        String ageStr = "";

        if (gender.equals("male")) {
            genderStr = "男";
        } else {
            genderStr = "女";
        }

        if (glass.equals("yes")) {
            glassStr = "戴眼镜";
        } else {
            glassStr = "不戴眼镜";
        }


        switch (age) {
            case "kid":
                ageStr = "儿童";
                break;
            case "child":
                ageStr = "少年";
                break;
            case "teenager":
                ageStr = "青少年";
                break;
            case "young":
                ageStr = "青年";
                break;
            case "prime":
                ageStr = "壮年";
                break;
            case "middle":
                ageStr = "中年";
                break;
            case "middleAged":
                ageStr = "中老年";
                break;
            case "old":
                ageStr = "老年";
                break;
        }

        long time = CalendarUtil.yyyy_MM_dd_T_HH_mm_SSSZToLong(eventTime);
        String myTime = TimeUtils.millis2String(time);


        if (!StringUtils.isEmpty(imgUrl)) {
            Glide.with(context)
                    .load(imgUrl)
                    .apply(BaseApplication.getRequestOptions())
                    .into((ImageView) helper.getView(R.id.iv_img));
        } else {
            helper.getView(R.id.iv_img).setBackgroundResource(R.mipmap.img_default_news);
        }

        if (!StringUtils.isEmpty(cameraName)) {
            helper.setText(R.id.tv_monitoring_name,cameraName);
        } else {
            helper.setText(R.id.tv_monitoring_name,"");
        }

        if (!StringUtils.isEmpty(myTime)) {
            helper.setText(R.id.tv_time,myTime);
        } else {
            helper.setText(R.id.tv_time,"");
        }

        helper.setText(R.id.tv_result,ageStr + "  " + genderStr + "  " + glassStr);
    }

}
